package com.shiyi.config;

import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.*;

public class PageNumberEvent extends PdfPageEventHelper {

    @Override
    public void onEndPage(PdfWriter writer, Document document) {
//        super.onEndPage(writer, document);
        PdfPTable pdfPTable = new PdfPTable(1);
        pdfPTable.setWidths(new float[]{1});
        pdfPTable.setTotalWidth(50);
        pdfPTable.setLockedWidth(true);
        pdfPTable.getDefaultCell().setBorder(0);
        PdfPCell pdfPCell = new PdfPCell(new Paragraph(writer.getPageNumber()));
        pdfPCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pdfPCell.setBorder(0);
        pdfPTable.addCell(pdfPCell);

        PdfContentByte directContentUnder = writer.getDirectContentUnder();
        Rectangle pageSize = document.getPageSize();
        float x = pageSize.getWidth();
        float y = pageSize.getBottom() - 10;
        pdfPTable.writeSelectedRows(0,-1,260,30,directContentUnder);



    }
}
